package com.zjj.lbw.interview.array;

/**
 * @author zhanglei.zjj
 * @description 去除数组中的重复项-基于快慢指针求解
 * @date 2023/8/31 22:03
 */
public class RemoveArrayDuplicates {
    public static int removeArrayDuplicates(int[] arr) {
        if (arr.length == 0) {
            return 0;
        }
        int slow = 0;
        for (int fast = 1; fast < arr.length; fast++) {
            if (arr[slow] != arr[fast]) {
                slow++;
                arr[slow] = arr[fast];
            }
        }
        return slow + 1;
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1, 2, 2, 3, 3,5};
        int i = removeArrayDuplicates(arr);
        System.out.println(i);
    }
}
